import 'package:flutter/cupertino.dart';
import 'dart:ui' as ui;

import 'package:flutter/material.dart';
///
/// [author]: liMing
/// [Date]: 2021-08-17  00:21
/// 绘制图片
class CustomCanvasImage extends CustomPainter {
  ui.Image image;
  Paint _paint;
  double strokeWidth=0.5;
  final Color color = Colors.blue;

  CustomCanvasImage(this.image){
    _paint = Paint()
      ..style = PaintingStyle.fill
      ..strokeWidth = strokeWidth
      ..color = color;
  }


  @override
  void paint(Canvas canvas, Size size) {
    canvas.translate(size.width/2, size.height/2);

    drawImages(canvas);
    canvas.drawCircle(Offset(0, 0), 6, _paint);
  }

  ///绘制图片
  drawImages(Canvas canvas){
    if(image!=null)
    canvas.drawImage(image,Offset(-image.width/2,-image.height/2), _paint);
  }

  @override
  bool shouldRepaint(covariant CustomCanvasImage oldDelegate) {
    return image!=oldDelegate.image;
  }
}
